//
//  YLLWelcomeViewController.swift
//  YLLSina
//
//  Created by 于玲玲 on 16/7/31.
//  Copyright © 2016年 itcast. All rights reserved.
//

import UIKit

class YLLWelcomeViewController: UIViewController {

    
    override func loadView() {
        view = bgImageView
    }
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()

        setupUI()

    }
    
    override func viewDidAppear(animated: Bool) {
        startAnimation()
    }

    private func setupUI(){
        
        view.addSubview(photoImageView)
        view.addSubview(messageLabel)
        
        //设置约束
        photoImageView.snp_makeConstraints { (make) in
            make.centerX.equalTo(view.snp_centerX)
            make.bottom.equalTo(view.snp_bottom).offset(-200)
        }
        
        messageLabel.snp_makeConstraints { (make) in
            make.centerX.equalTo(view.snp_centerX)
            make.top.equalTo(photoImageView.snp_bottom).offset(20)
        }
        
    }
    
    private func startAnimation(){
        
        self.photoImageView.snp_updateConstraints { (make) in
            make.bottom.equalTo(view.snp_bottom).offset(-UIScreen.mainScreen().bounds.size.height + 200)
        }
                                                                                                                                       //为什么是括号
        UIView.animateWithDuration(2.0, delay: 0, usingSpringWithDamping: 0.7, initialSpringVelocity: 10, options: [], animations: { 
            self.view.layoutIfNeeded()
            }) { (_) in
                printLog("动画完成")
                NSNotificationCenter.defaultCenter().postNotificationName("kNotificationChangeViewController", object: self)
        }
        
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()

    }
    

    //懒加载控件
    
    ///背景图片
    private lazy var bgImageView: UIImageView = {
        
        let img = UIImageView()
        
        img.image = UIImage(named: "ad_background")
        
        return img
        
    }()
    
  ///头像
    private lazy var photoImageView: UIImageView = {
        
        let img = UIImageView()
        
        img.image = UIImage(named: "avatar_default_big")
        
        img.layer.cornerRadius = 170/2/2
        
        img.layer.borderColor = UIColor.grayColor().CGColor
        
        img.layer.borderWidth = 2
        
        img.layer.masksToBounds = true
        
//        img.clipsToBounds
        
        return img
        
    }()
    
    ///提示语
    
    private lazy var messageLabel: UILabel = {
    
    let message = UILabel()
        
        message.text = "欢迎归来"
        message.font = UIFont.systemFontOfSize(16)
        message.textColor = UIColor.darkGrayColor()
        message.textAlignment = .Center
        
        return message
    
    
    }()
    
    

}
